\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{tutor}[15/08/2010 Randomized questions system]

% pass unknown options to article
\LoadClass[11pt]{article}
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{article}%
}

% flag to operate in quizz mode or item mode 
\newif\ifmakequizz
\makequizzfalse
\DeclareOption{makequizz}{\makequizztrue}
\ProcessOptions\relax



% TODO: learn how to do this properly. I don't want to throw errors if the
% user loads the "color" package again
\RequirePackage{color}
\RequirePackage{verbatim}
\RequirePackage{graphicx}
\RequirePackage{amsmath}

% default formatting
\RequirePackage{nopageno}
\RequirePackage[a4paper]{geometry}
\geometry{verbose,tmargin=1.5cm,bmargin=2cm,lmargin=1.75cm,rmargin=1.75cm}

% prevent plastex from expanding some user-defined macros and environments
% (i don't think this is necessary!)
%\newif\ifplastex
%\plastexfalse

%
% SPECIAL ENVIRONMENTS
%

% python environment
\newenvironment{python}{\small\color{red}\verbatim}{\endverbatim}

% special environments
\newenvironment{itembody}{\bgroup}{\egroup}
\newenvironment{items}{\bgroup}{\egroup}

% special types of questions
\newenvironment{multiplechoice}{\enumerate}{\endenumerate}
\newenvironment{truefalse}{\itemize}{\enditemize}

% \py command (code adapted from LaTeX's \verb).
\def\pyesc#1{{\color{green}#1}}

{\catcode`\ =\active%
\gdef\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}

\begingroup 
  \catcode `|=0 
  \catcode `[= 1
  \catcode `]=2 
  \catcode `\{=12 
  \catcode `\}=12
  \catcode `\\=12 
  |gdef|@xbracketverbatim#1\end{bracketverbatim}[#1|end[bracketverbatim]]
  |gdef|@sxbracketverbatim#1\end{bracketverbatim*}[#1|end[bracketverbatim*]]
|endgroup

\def\bracketverbatim@font{\small\ttfamily}

\def\@makeother#1{\catcode`#112\relax}

\let\bracketverb@balance@group\@empty

\def\bracketverb@egroup{\global\let\bracketverb@balance@group\@empty\egroup}

\begingroup
  \obeylines%
  \gdef\bracketverb@eol@error{\obeylines%
    \def^^M{\bracketverb@egroup\@latex@error{%
            \noexpand\bracketverb ended by end of line}\@ehc}}%
\endgroup


\def\py{
  \relax
  \ifmmode\hbox\else\leavevmode\null\fi
  \bgroup
    \bracketverb@eol@error
    \let\do\@makeother 
    \dospecials
    \bracketverbatim@font
    \color{blue}
    \@noligs
    \@bracketverb}

\def\@bracketverb#1{
  \if\noexpand#1\noexpand{
  \else
    \@latex@error{\noexpand\py must be followed by a \{ character, not "#1"}\@ehc}
  \fi
  \@vobeyspaces\frenchspacing
  \catcode`\}\active
  \lccode`\~`\}
  
  \gdef\bracketverb@balance@group{\bracketverb@egroup
     \@latex@error{\noexpand\bracketverb illegal in command argument}\@ehc}%
  \aftergroup\bracketverb@balance@group
  \lowercase{\let~\bracketverb@egroup}
  }%
  
% meta attributes: holds metadata
\def\metadata#1{}
\def\author{}
\def\creationdate{}
\def\status{}
\def\priordifficulty{}
\def\priortime{}
\def\itemtype{}

%\newcommand{solution}{\item}
\def\solution{\item}

% the \choice and \explanation commands
\ifmakequizz
  \def\choice#1{\item}
\else 
  \def\choice#1{\item (#1)}
\fi
  
\def\explanation{\\}

